<template>
  <Table
    ref="tableRef"
    :url="URL_QUERYROLELIST"
    :columns="data.columns"
    :handles="data.handles"
    :toolbar="data.toolbar"
    :query="data.query"
  ></Table>
</template>

<script lang="ts" setup name="roleList">
import Table from '@/components/table/index.vue';
import { URL_QUERYROLELIST } from '@/service/apis/auth';

const router = useRouter();

const tableRef = ref();

const emit = defineEmits(['get-update']);
onActivated(() => {
  emit('get-update', (flag: boolean) => {
    if (flag) {
      tableRef.value?.getData();
    }
  });
});

const data = reactive({
  columns: [
    {
      prop: 'roleName',
      label: '角色名称',
    },
    {
      prop: 'createByName',
      label: '创建人',
    },
    {
      prop: 'createTime',
      label: '创建时间',
    },
  ],
  handles: [
    {
      label: '详情',
      handle: (row: any) => {
        console.log('详情 ---', row);
        router.push({
          name: 'roleDetail',
          query: { id: row.id },
        });
      },
    },
    {
      label: '修改',
      permission: 'roleList.edit',
      handle: (row: any) => {
        console.log('编辑---', row);
        router.push({
          name: 'roleEdit',
          query: { id: row.id },
        });
      },
    },
  ],
  toolbar: [
    {
      label: '新增',
      permission: 'roleList.add',
      icon: 'icon-add',
      type: 'primary',
      handle: (row: any) => {
        router.push({
          name: 'roleAdd',
        });
      },
    },
  ],
  query: [
    {
      label: '角色名称',
      prop: 'roleName',
      comName: 'input',
      props: {
        placeholder: '请输入角色名称',
      },
    },
  ],
});
</script>